package com.example.skipad

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.widget.SwitchCompat
import android.content.Intent
import android.provider.Settings
import android.view.MotionEvent


class MainActivity : AppCompatActivity() {


    private lateinit var switchBtn: SwitchCompat

    @SuppressLint("ClickableViewAccessibility")
    override
    fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        //开启无障碍
        switchBtn = findViewById(R.id.switch_btn)
        switchBtn.isChecked =
            Util.isAccessibilitySettingsOn(this, SkipService::class.java.canonicalName)

        switchBtn.setOnTouchListener { _, motionEvent ->
            if (motionEvent.action == MotionEvent.ACTION_UP) {
                val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
                startActivity(intent)
                return@setOnTouchListener true
            }
            false
        }


    }


    override fun onBackPressed() {
        moveTaskToBack(true)
    }

    override fun onResume() {
        super.onResume()
        switchBtn.isChecked =
            Util.isAccessibilitySettingsOn(this, SkipService::class.java.canonicalName)
//        if (switchBtn.isChecked) {
//            //启动服务
//            startService(Intent(this, SkipService::class.java))
//        }
    }

}